package com.wlyy.bcwlw.common.export2excel.web;

import java.util.ArrayList;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import com.wlyy.bcwlw.base.BaseController;
import com.wlyy.bcwlw.common.export2excel.entity.TableCell;
import com.wlyy.bcwlw.common.export2excel.service.Export2ExcelService;

@Controller
public class Export2ExcelController extends BaseController{

	@Autowired
	private Export2ExcelService export2ExcelService;
	
	
	@RequestMapping("/excelUtils/exportTable")
	public String exportTable(HttpServletRequest request,HttpServletResponse response){
		
		String tableArrayData = request.getParameter("tableArrayData");
		
		String[] array1 = StringUtils.split(tableArrayData,"@");
		
		List<List<TableCell>> tableCellList = new ArrayList<List<TableCell>>();
		for(int i=0;i<array1.length;i++){
			String [] array2 = StringUtils.split(array1[i], "#");
			List<TableCell> list = new ArrayList<TableCell>();
			for(int j=0;j<array2.length;j++){
				String[] array3 = StringUtils.split(array2[j], "$");
				TableCell tableCell = new TableCell(array3[0], Integer.valueOf(array3[1]), Short.valueOf(array3[2]));
				list.add(tableCell);
			}
			tableCellList.add(list);
		}
		
		export2ExcelService.exportTable(response, tableCellList);
		
		return null;
		
	}
}
